package day08;

import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/7/9
 */
public class Homework01 {
    /**
     *      需求：
     *          键盘录入一个字符串，然后定义一个方法判断该字符串是否是对称字符串。
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String s = sc.nextLine();
        System.out.println("-----------------");
        isSymmetrical(s);
        System.out.println("-----------------");
        checkString(s);
        System.out.println("-----------------");
        checkString_2(s);
    }

    private static void checkString_2(String s) {
        String s1 = "";
        for (int length = s.length()-1; length > 0; length--) {
            char c = s.charAt(length);
            s1 += c;
        }
        if (s1.equals(s)) {
            System.out.println("字符串\t" + s + "\t是对称字符串。");
        } else {
            System.out.println("字符串\t" + s + "\t不是对称字符串。");
        }
    }

    public static void isSymmetrical(String s) {
        lo:
        while (true) {
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
                    System.out.println("字符串\t" + s + "\t不是对称字符串。");
                    break lo;
                }
            }
            System.out.println("字符串\t" + s + "\t是对称字符串。");
            break;
        }
    }

    public static void checkString(String s) {
        char[] ch = s.toCharArray();
        for (int start = 0, end = ch.length - 1; start < end; start++, end--) {
            int temp = ch[start];
            ch[start] = ch[end];
            ch[end] = ch[start];
        }
        String s1 = new String (ch);
        if (s1.equals(s)) {
            System.out.println("字符串\t" + s + "\t是对称字符串。");
        } else {
            System.out.println("字符串\t" + s + "\t不是对称字符串。");
        }
    }
}
